﻿using System;
using System.Collections;
using System.Web;
using System.Web.Caching;

public class CacheHelper
{
    public static void setCache(string key, object value, TimeSpan expire)
    {
        Cache adminCache = HttpRuntime.Cache;

        adminCache.Insert(key, value, null, DateTime.Now.Add(expire), Cache.NoSlidingExpiration);
    }

    public static object getCache(string key)
    {
        Cache adminCache = HttpRuntime.Cache;

        return adminCache[key];
    }

    public static void clearAllCache()
    {
        foreach (DictionaryEntry dEntry in HttpContext.Current.Cache)
        {
            HttpContext.Current.Cache.Remove(dEntry.Key.ToString());
        }
    }

    public static void removeCache(string cacheName)
    {
        HttpContext.Current.Cache.Remove(cacheName);
    }
}
